package draw.common.config;

import draw.common.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class webConfig implements WebMvcConfigurer {

    @Value("${file.local-path}")
    String localPath;
    @Autowired
    LoginInterceptor loginInterceptor;

    List<String> excludeUrls = Arrays.asList("/**/*.html",
            "/css/**",
            "/js/**",
            "/pic/**",
            "/**/*.jpg",
            "/**/*.png",
            "/favicon.ico",
            "/**/register",
            "/**/login",
            "/**/email",
            "/**/lottery-picture/**",
            "/**/verification-code/send",
            "/**/winning-records/show"
    );


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludeUrls);
    }

    /**
     * 资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/lottery-picture/**")
                .addResourceLocations("file:"+localPath+"/");
    }
}

